import json
import logging
import os

from coin2.support.product_info.spot_bithumb_v2 import convert_coin1_constants


pi_file = 'data/coin2/product_info/Spot.Bithumb.v2.json'
with open(pi_file) as f:
  static_constants = convert_coin1_constants(json.load(f)['product_infos'])

dynamic_constants = {}
if int(os.getenv('USE_DYNAMIC_SYMBOL', 0)):
  try:
    from coin2.support.product_info.spot_bithumb_v2 import gen_coin1_constants
    dynamic_constants = gen_coin1_constants()
  except Exception as e:
    logging.error('Failed to use bithumb dynamic symbols! %s', e)

coin_list = list(set(
    static_constants.get('coin_list', []) +
    dynamic_constants.get('coin_list', [])))
quote_currency_list = ["KRW"]
currency_list = coin_list + quote_currency_list
currency_list_all = currency_list + ["ALL"]

# errors
# 0000  SUCCESS
# 5100  Bad Request
# 5200  Not Member
# 5300  Invalid Apikey
# 5302  Method Not Allowed
# 5400  Database Fail
# 5500  Invalid Parameter
# 5600  CUSTOM NOTICE (output the error message in each situation)
# 5900  Unknown Error
RETURN_CODE_SUCCESS = "0000"
RETURN_CODE_UNKNOWN_ERROR = "5600"

# bithumb currency code to name mapping can be found here.
# https://r2.bithumb.com/resources/js/language/english_lang_new.js?v=bithumb.2.0
bithumb_cointype_to_name = {
    "C0100": "KRW",
    "C0101": "BTC",
    "C0102": "ETH",
    "C0103": "DASH",
    "C0104": "LTC",
    "C0105": "ETC",
    "C0106": "XRP",
    "C0107": "BCH",
    "C0108": "XMR",
    "C0109": "ZEC",
    "C0110": "QTUM",
    "C0111": "BTG",
    "C0112": "EOS",
    "C0115": "ICX",
    "C0224": "BSV",
    "C0118": "ELF",
    "C0123": "KNC",
    "C0117": "TRX",
    "C0150": "ADA",
    "C0168": "LINK",
    "C0504": "XLM",
    "C0138": "STEEM",
    "C0207": "TMTG",
    "C0255": "FCT",
    "C0524": "BHP",
    "C0156": "THETA",
    "C0179": "RNT",
    "C0256": "FNB",
    "C0195": "INS",
    "C0537": "META",
    "C0283": "EL",
}

min_order_qty = 0.0001
